﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace BLL.Workflows
{
    public class Logger
    {
        private static EventLog _EventLog;
        private static readonly string _LogName = "WORKFLOW ENGINE";
        private static readonly string _LogSource = "Workflow";

        static Logger()
        {
            _LogName = ConfigurationManager.AppSettings.Get("EventLogName");
            _LogSource = ConfigurationManager.AppSettings.Get("EventLogSource");
            RegisterEventLog();
        }

        static void RegisterEventLog()
        {
            if (!EventLog.SourceExists(_LogSource))
            {
                EventLog.CreateEventSource(_LogSource, _LogName);
            }
            _EventLog = new EventLog(_LogName, ".", _LogSource);
            _EventLog.MaximumKilobytes = 4096;
            _EventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 7);
        }

        public static void Info(string info)
        {
            _EventLog.WriteEntry(info, EventLogEntryType.Information);
        }

        public static void Error(string error)
        {
            _EventLog.WriteEntry(error, EventLogEntryType.Error);
        }

        public static void Warn(string warn)
        {
            _EventLog.WriteEntry(warn, EventLogEntryType.Warning);
        }
    }
}
